package cn.yangliu.service.impl;

import cn.yangliu.service.JpaUserService;
import cn.yangliu.entity.JpaUser;
import cn.yangliu.jpa.repository.UserRepository;
import cn.yangliu.jpa.service.impl.JpaServiceImpl;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * 作者 杨柳
 * 创建时间 2017-08-27 15:30
 */
@Service
@Transactional
public class JpaUsererviceImpl extends JpaServiceImpl<JpaUser,Long,UserRepository> implements JpaUserService<UserRepository> {


    @Resource
    private UserRepository userRepository;
    @Override
    @Cacheable(cacheNames = "jpa_user", key = "#root.targetClass.name + #root.methodName",
            unless = "#result eq null", cacheManager = "cacheManager")
    public JpaUser findAccountByUsernameAndPassword(String username, String password) {
      /*  JpaUser u = userRepository.getOne(1L);
        u.getAge();
        return u;*/
        return  userRepository.getOne(1L);
    }

    @Override
    public void insert(JpaUser user) {
        userRepository.save(user);
    }
}
